var i4common = {

    cacheClientInfo: new HashMap(),
    cacheScrollTop: new HashMap(),
    cacheDeviceInfo: new HashMap(),
    cacheScrollPage: new HashMap(),


    pcguid: '0',

    pc_vs: '0',
    /**
     * 调试模式
     * @param 1：开启 0：关闭
     */
    DEBUG: 1,

    iosVersion: '',
    /**
     * 连接设备列表
     */
    deviceArray: [],

    model: '',
    /**
     * 客户端交互，发送消息到客户端
     * @param {} _val
     */
    callToClient: function (_param) {
        // alert("网页发消息到客户端："+_param);
        // alert("网页发消息到客户端："+_param);
        //        i4common.clientCallPage("{ \"code\" : 10, \"device\" : [ { \"capacity\" : 16, \"device\" : \"iPad Air2 Wi-Fi\", \"model\" : \"iPad5,3\", \"name\" : \"Heng的 iPad\", \"udid\" : \"b84949d802a60a09943bc88b09f72733be0994cd\" } ], \"tag\" : 2 }")
        //        i4common.clientCallPage('{"code" : 10,"success" :  1, "tag" :  1, "device" : [{"udid":"udid","device":"iPhone4","model":"iPhone3,1","name":"Loong\'s iPhone爱思助手测试机","capacity":"64"},{"udid":"udid","device":"iPad2","model":"iPad3,1","name":"2222222","capacity":"128"}]}');
        //        i4common.clientCallPage('{"code" : 10,"success" :  1, "tag" :  1, "device" : []}');
        //    console.log(_param);
        //        var _p = eval('('+_param+')');
        //        if(_p.code == 13){
        //            i4common.tmp_info = _p.param.info;
        //        }
        // console.log(_param)
        try {
            i4Client.fxSendWebJson(_param);
        } catch (e) {
            // console.log(e);
        }
    },

    /**
     * 客户端交互，发送消息到客户端，等待客户端响应
     * @param {} _param
     */
    callToClientWait: function (_param) {
        try {
            return i4Client.fxGetClientInfo(_param);
            //            return i4common.tmp_info;
        } catch (e) {
            console.log(e);
            return '';
        }
    },

    /**
     * 客户端交互，接收客户端发送消息
     * @param {} param
     */
    clientCallPage: function (_param) {
        // console.log("网页接收客户端消息：");
        // console.log(_param);
        // alert("网页接收客户端消息："+_param);
        if (_param) {
            try {
                var p = eval('(' + _param + ')');
                if (p != null) {
                    if (p.code == 1 || p.code == 4) {
                        //应用下载状态变更  code == 1
                        //本地、设备应用列表  code == 4
                        //                        if(p.code == 1){
                        //                            alert(_param);
                        //                        }
                        i4app.readClientAppInfo(p.code, p.udid, p.param);
                    } else if (p.code == 10) {

                        // console.log(_param);
                        // alert("已连接设备信息："+_param);

                        //                        alert(_param);
                        i4common.deviceArray = p.device;
                        //已连接设备信息
                        i4common.showDeviceInfo(p.tag, p.device);
                    } else if (p.code == 11) {
                        // console.log(_param);
                        i4common.showAppIdInfo(p.param);
                    } else if (p.code == 27) {
                        // console.log(_param);
                        var set = null;
                        for (var index = 0; index < i4common.deviceArray.length; index++) {
                            if (i4common.deviceArray[index].udid == p.udid) {
                                set = i4common.deviceArray[index];
                            }
                        }
                        if (set != null) {
                            i4common.setDeviceFun(set);
                        }

                    } else if (p.code == 17) {
                        i4common.pcguid = p.pcguid.replace('{', '').replace('}', '');
                    }
                }
            } catch (e) {
                console.log(e);
            }
        }
    },
    setDeviceFun: function (obj) {
        var _ds = obj;
        // 设备类型 默认：没有设备
        var deviceType = null;
        var device = _ds.device;
        // _ds.selected = true;
        i4common.model = _ds.model;
        i4common.iosVersion = _ds.iosversion;

        if (device.indexOf('iPad') >= 0) {
            deviceType = 'iPad';
        } else if (device.indexOf('iPhone') >= 0) {
            deviceType = 'iPhone';
        } else if (device.indexOf('iPod') >= 0) {
            deviceType = 'iPod';
        }
        $('.left .device .deviceType span').removeClass();
        $('.left .device .deviceType span').addClass(deviceType);

        $('.left .device .deviceType font').html((_ds.name.length > 0 ? ($.trim(_ds.name).length == 0 ? '&nbsp;' : _ds.name) : $.trim(_ds.device)));
        $('.left .device .deviceType font').attr('title', $('.left .device .device_name').text());

        $('.left .device .device_name').html($.trim(_ds.device));
        $('.left .device .device_name').attr('title', $.trim(_ds.device));
        $('.left .device .deviceSize font').removeClass();
        $('.left .device .deviceSize font').addClass('gb' + _ds.capacity);

        $('.tag li').removeClass('active');
        $('.tag li').each(function () {
            if (_ds.udid == $(this).attr('_val')) {
                $(this).addClass('active');
            }
        });

        i4common.cacheClientInfo.remove('current_device');
        i4common.cacheClientInfo.put('current_device', _ds);
        if (typeof i4app != 'undefined') {
            i4app.callbackByDeviceUpdate();
        }


    },
    /**
     * 展示设备信息
     * @param {} _param
     */
    showDeviceInfo: function (tag, _param) {
        if (_param != null) {
            $('.left .device .no').hide();
            $('.left .device .show').show();
            var _d = _param[0];
            for (var i = 0; i < _param.length; i++) {

                if (_param[i].selected == true) {
                    _d = _param[i];
                    break;
                }
            }

            _d.name = _d.name.replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#039;');
            _d.device = _d.device.replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#039;');


            // var curr_dev = null;
            // if (i4common.cacheClientInfo.containsKey("current_device")) {
            //     curr_dev = i4common.cacheClientInfo.get("current_device");
            // }
            //页面刷新后， 对比显示哪台设备
            // if (curr_dev != null) {
            //     var _show_dev = null;
            //     for (var i = 0; i < _param.length; i++) {
            //         _d = _param[i];
            //         if (_d.udid == curr_dev.udid) {
            //             _show_dev = _d;
            //             break;
            //         }
            //     }
            //     if (_show_dev == null) {
            //         _d = _param[0];
            //     }
            // } else {
            //     _d = _param[0];
            // }
            // _d.selected = "true";

            i4common.cacheClientInfo.remove('current_device');
            i4common.cacheClientInfo.put('current_device', _d);

            i4common.setDeviceFun(_d);
            var html = '';
            if (_param.length > 1) {
                $('.left .device .show a').show();
                i4common.cacheDeviceInfo.clear();
                for (var i = 0; i < _param.length; i++) {
                    _d = _param[i];
                    i4common.cacheDeviceInfo.remove(_d.udid);
                    i4common.cacheDeviceInfo.put(_d.udid, _d);

                    html += '<li _val="' + _d.udid + '"  title="' + (_d.name.length > 0 ? _d.name : $.trim(_d.device)) + '[' + $.trim(_d.device) + ']" class="' + (_d.selected == true ? 'active' : '') + '">' + (_d.name.length > 0 ? ($.trim(_d.name).length == 0 ? '&nbsp;' : _d.name) : $.trim(_d.device)) + '</li>';

                }
                $('.left .device .show ul').html(html);
                $('.left .device .show li').click(function () {
                    var val = $(this).attr('_val');
                    var _d = i4common.cacheClientInfo.get('current_device');

                    if (_d.udid != val) {
                        var _ds = i4common.cacheDeviceInfo.get(val);
                        if (_ds != null) {
                            // console.log(_ds);
                            // i4common.showDeviceInfo(1, _ds);

                            //设备信息变更后回调
                            // if (typeof i4app != 'undefined') {

                            i4common.setDeviceFun(_ds);
                            console.log('切换设备：' + '{"code" : 27,"tag" : ' + tag + ',"udid":"' + _ds.udid + '"}');
                            var _param = '{"code" : 27,"tag" : ' + tag + ',"udid":"' + _ds.udid + '"}';
                            i4common.callToClient(_param);

                            // i4common.showDeviceInfo(tag,_d);
                            // }
                        }

                    }
                });
            } else {
                $('.left .device .show a').hide();
                $('.left .device .show .tag').hide();
            }
        } else {
            i4common.model = '';
            i4common.iosVersion = '';

            i4common.cacheClientInfo.remove('current_device');
            $('.left .device .show').hide();
            $('.left .device .no').show();
        }
        //设备信息变更后回调
        if (tag == 1) {
            i4app.callbackByDeviceUpdate();
        } else if (tag == 8) {
            i4ipsw.callbackByDeviceUpdate(_param);
        } else if (tag == 3) {
            i4paper.callbackByDeviceUpdate(_param);
        }
        return;
        if ($('#device_info').length == 1) {
            if (_param != null && _param.length > 0) {
                var _d = _param[0];
                var curr_dev = null;
                if (i4common.cacheClientInfo.containsKey('current_device')) {
                    curr_dev = i4common.cacheClientInfo.get('current_device');
                }

                //页面刷新后， 对比显示哪台设备
                if (curr_dev != null) {
                    var _show_dev = null;
                    for (var i = 0; i < _param.length; i++) {
                        _d = _param[i];
                        if (_d.udid == curr_dev.udid) {
                            _show_dev = _d;
                            break;
                        }
                    }
                    if (_show_dev == null) {
                        _d = _param[0];
                    }
                } else {
                    _d = _param[0];
                }

                //                if(curr_dev != null){
                //                    alert(curr_dev.device + "  ==  " +_d.device);
                //                }else{
                //                    alert("+  ==  " +_d.device);
                //                }


                i4common.cacheClientInfo.remove('current_device');
                i4common.cacheClientInfo.put('current_device', _d);
                // 设备类型 默认：没有设备
                var deviceType = 'device_notDevice';
                var device = _d.device;

                if (device.indexOf('iPad') >= 0) {
                    deviceType = 'iPad';
                } else if (device.indexOf('iPhone') >= 0) {
                    deviceType = 'iPhone';
                } else if (device.indexOf('iPod') >= 0) {
                    deviceType = 'iPod';
                }
                var html = '<div class="device_' + deviceType + '"></div>' +
                    '<ul>' +
                    '   <li class="device_type" style="width:' + (_param.length > 1 ? 89 : 114) + 'px;  white-space:nowrap; overflow:hidden; text-overflow:ellipsis;" title="' + (_d.name.length > 0 ? _d.name : $.trim(_d.device)) + '">' + (_d.name.length > 0 ? ($.trim(_d.name).length == 0 ? '&nbsp;' : _d.name) : $.trim(_d.device)) + '</li>' +
                    '   <li class="device_disk gb' + _d.capacity + '"></li>' +
                    '   <li class="device_name" style="width:114px;  white-space:nowrap; overflow:hidden; text-overflow:ellipsis;" title="' + $.trim(_d.device) + '">' + $.trim(_d.device) + '</li>' +
                    '</ul>';
                if (_param.length > 1) {
                    i4common.cacheDeviceInfo.clear();
                    html += '<a href="javascript:;" class="device_Switch"><span>切换设备</span></a>' +
                        '<p>';
                    for (var i = 0; i < _param.length; i++) {
                        _d = _param[i];
                        i4common.cacheDeviceInfo.remove(_d.udid);
                        i4common.cacheDeviceInfo.put(_d.udid, _d);
                        //                        html += '<a href="javascript:;" _val="'+_d.udid+'" title="'+(_d.name.length>0?$.trim(_d.name):$.trim(_d.device))+'['+$.trim(_d.device)+']" style="width:100px;  white-space:nowrap; overflow:hidden; text-overflow:ellipsis;">'+(_d.name.length>0?($.trim(_d.name).length==0?'&nbsp;':$.trim(_d.name)):$.trim(_d.device))+'</a>';
                        html += '<a href="javascript:;" _val="' + _d.udid + '" title="' + (_d.name.length > 0 ? _d.name : $.trim(_d.device)) + '[' + $.trim(_d.device) + ']">' + (_d.name.length > 0 ? ($.trim(_d.name).length == 0 ? '&nbsp;' : _d.name) : $.trim(_d.device)) + '</a>';
                    }
                    html += '</p>';
                }
            } else {
                i4common.cacheClientInfo.remove('current_device');
                var html = '<div class="device_notDevice"></div>' +
                    '<ul>' +
                    '   <li class="device_type">未连接设备</li>' +
                    '   <li class="device_text">下载的文件将保存在您的电脑里</li>' +
                    '</ul>';
            }
            $('#device_info').html(html);
            /**
             * 绑定切换设备信息事件
             */
            var bindEvent = function () {
                var DeviceSwitchButton = $('.device_Switch');
                if (DeviceSwitchButton.length > 0) {
                    var deviceList = DeviceSwitchButton.next('p');
                    DeviceSwitchButton.off();
                    deviceList.off();
                    DeviceSwitchButton.on('click', function () {
                        if (deviceList.css('display') == 'block') {
                            deviceList.hide();
                        } else {
                            deviceList.show();
                        }
                        return false;
                    });
                    deviceList.on('click', 'a', function (e) {
                        var _cell = $(e.target);
                        var _d = i4common.cacheClientInfo.get('current_device');
                        if (_d.udid != _cell.attr('_val')) {
                            showDeviceInfo(_cell.attr('_val'));
                        }
                        deviceList.hide();
                    });
                }
            };
            /**
             * 切换设备后 重构页面显示设备信息
             */
            var showDeviceInfo = function (udid) {
                var _d = i4common.cacheDeviceInfo.get(udid);
                if (_d != null) {
                    i4common.cacheClientInfo.remove('current_device');
                    i4common.cacheClientInfo.put('current_device', _d);
                    var _keys = i4common.cacheDeviceInfo.keySet();

                    // 设备类型 默认：没有设备
                    var deviceType = 'device_notDevice';
                    var device = _d.device;

                    if (device.indexOf('iPad') >= 0) {
                        deviceType = 'iPad';
                    } else if (device.indexOf('iPhone') >= 0) {
                        deviceType = 'iPhone';
                    } else if (device.indexOf('iPod') >= 0) {
                        deviceType = 'iPod';
                    }


                    var html = '<div class="device_' + deviceType + '"></div>' +
                        '<ul>' +
                        '   <li class="device_type" style="width:' + (_param.length > 1 ? 89 : 114) + 'px;  white-space:nowrap; overflow:hidden; text-overflow:ellipsis;" title="' + (_d.name.length > 0 ? _d.name : $.trim(_d.device)) + '">' + (_d.name.length > 0 ? ($.trim(_d.name).length == 0 ? '&nbsp;' : _d.name) : $.trim(_d.device)) + '</li>' +
                        '   <li class="device_disk gb' + _d.capacity + '"></li>' +
                        //                                '   <li class="device_name" style="width:114px;  white-space:nowrap; overflow:hidden; text-overflow:ellipsis;" title="'+(_d.name.length>0?$.trim(_d.name):$.trim(_d.device))+'">'+(_d.name.length>0?($.trim(_d.name).length==0?'&nbsp;':$.trim(_d.name)):$.trim(_d.device))+'</li>' +
                        '   <li class="device_name" style="width:114px;  white-space:nowrap; overflow:hidden; text-overflow:ellipsis;" title="' + $.trim(_d.device) + '">' + $.trim(_d.device) + '</li>' +
                        '</ul>';
                    if (_keys.length > 1) {
                        html += '<a href="javascript:;" class="device_Switch"><span>切换设备</span></a>' +
                            '<p>';
                        for (var i = 0; i < _keys.length; i++) {
                            _d = i4common.cacheDeviceInfo.get(_keys[i]);
                            i4common.cacheDeviceInfo.remove(_d.udid);
                            i4common.cacheDeviceInfo.put(_d.udid, _d);
                            //                            html += '<a href="javascript:;" _val="'+_d.udid+'" title="'+(_d.name.length>0?$.trim(_d.name):$.trim(_d.device))+'['+$.trim(_d.device)+']" style="width:100px;  white-space:nowrap; overflow:hidden; text-overflow:ellipsis;">'+(_d.name.length>0?($.trim(_d.name).length==0?'&nbsp;':$.trim(_d.name)):$.trim(_d.device))+'</a>';
                            html += '<a href="javascript:;" _val="' + _d.udid + '" title="' + (_d.name.length > 0 ? _d.name : $.trim(_d.device)) + '[' + $.trim(_d.device) + ']">' + (_d.name.length > 0 ? ($.trim(_d.name).length == 0 ? '&nbsp;' : _d.name) : $.trim(_d.device)) + '</a>';
                        }
                        html += '</p>';
                    }
                    $('#device_info').html(html);
                    bindEvent();
                    /*//设备信息变更后回调
                    i4app.callbackByDeviceUpdate();*/
                    //设备信息变更后回调
                    if (typeof i4app != 'undefined') {
                        i4app.callbackByDeviceUpdate();
                    }
                }
            };
            bindEvent();
        }
        //设备信息变更后回调
        if (tag == 1) {
            i4app.callbackByDeviceUpdate();
        } else if (tag == 8) {
            i4ipsw.callbackByDeviceUpdate(_param);
        } else if (tag == 3) {
            i4paper.callbackByDeviceUpdate(_param);
        }
    },


    /**
     * 展示绑定AppleID
     * @param {} _param
     */
    showAppIdInfo: function (_param) {
        var _d = _param;
        if (_param != null && _param.isbind == 1) {
            $('.u-appleId span').removeClass('no');
            $('.u-appleId span font').text('Apple ID：');
            $('.u-appleId .bindAppId').text(_d.bindid);
            $('.u-appleId .bindAppId').attr('title', _d.bindid);
        } else {
            $('.u-appleId span').addClass('no');
            $('.u-appleId span font').text('未绑定Apple ID');
            $('.u-appleId .bindAppId').text('立即绑定');
            $('.u-appleId .bindAppId').attr('title', '');
        }
        return;
        if ($('#bind_appleid_info').length == 1) {
            var html = '';
            if (_param != null && _param.isbind == 1) {
                var _d = _param;
                //                var html = '<a href="javascript:;" class="appleid_mail" id="bind_appid_btn" title="'+_d.bindid+'">'+_d.bindid+'</a>' +
                //                                '<p>将使用此 Apple ID</p>' +
                //                                '<p>从苹果商店代购免费应用</p>';
                html = '<p>已绑定 Apple ID</p>' +
                    '<a href="javascript:;" class="appleid_mail" id="bind_appid_btn" title="' + _d.bindid + '">' + _d.bindid + '</a>';
                //                if(_d.country){
                //                    html += '<dl><dt>AppleID 所属地区</dt><dd>'+_d.country+'</dd></dl>';
                //                }
            } else {
                //                var html = '<a href="javascript:;" class="appleid_mail" id="bind_appid_btn">立即绑定 Apple ID</a>' +
                //                                '<p>未绑定 Apple ID</p>' +
                //                                '<p>将自动从爱思助手下载应用</p>';
                html = '<p class="fcRed">未绑定 Apple ID</p>' +
                    '<a href="javascript:;" class="appleid_mail" id="bind_appid_btn">立即绑定</a>' +
                    //                        '<a href="javascript:;" class="appleid_mail" id="bind_appid_info_btn">了解详情</a>';
                    '<a href="http://url.i4.cn/EFbyymaa" target="_blank" class="appleid_mail">了解详情</a>';
            }
            $('#bind_appleid_info').html(html);
            $('#bind_appleid_info').show();
            if ($('#bind_appid_btn').length > 0) {
                $('#bind_appid_btn').unbind();
                $('#bind_appid_btn').bind('click', function (e) {
                    var _val = '{"code":12, "tag":1}';
                    i4common.callToClient(_val);
                });
            }
            if ($('#bind_appid_info_btn').length > 0) {
                $('#bind_appid_info_btn').unbind();
                $('#bind_appid_info_btn').bind('click', function (e) {
                    var _val = '{"code":12, "tag":1}';
                    i4common.callToClient(_val);
                });
            }
        }
    },

    getPosit: function (topValue, bufferArr) {
        //        console.log(topValue + "  ==  " + bufferArr.length);
        if (bufferArr.length == 1) {
            return 1;
        } else {
            for (var i = 0, len = bufferArr.length; i < len; i++) {
                //                console.log(topValue + "  --  " + bufferArr.eq(i)[0].scrollTop - 518*0.4);
                if (topValue < bufferArr.eq(i)[0].scrollTop - 518 * 0.4) {
                    if (i == 0) return 1;
                    return i;
                }
            }
        }
    },

    /**
     * 滚动条到底部自动加载事件绑定
     * @param {} containerObj
     * @param {} pageNo
     * @param {} cb
     */
    listScrollChangeEvent: function (parentContainerObj, containerObj, pageNo, cb) {
        if (pageNo == 2) {
            i4common.cacheScrollPage.remove(containerObj.attr('id'));
        }
        if (containerObj != null && containerObj.find('#bottom_loading_end').length == 0) {
            var topBuffer = [0];
            if (i4common.cacheScrollPage.containsKey(containerObj.attr('id'))) {
                topBuffer = i4common.cacheScrollPage.get(containerObj.attr('id'));
            }
            topBuffer.push(containerObj[0].scrollHeight);
            i4common.cacheScrollPage.put(containerObj.attr('id'), topBuffer);
            var bindFun = function () {
                if (pageNo == 1) {
                    containerObj[0].scrollTop = 0;
                }
                containerObj.unbind('scroll');
                containerObj.scroll(function () {
                    var obj = containerObj[0];
                    var topBuffer = i4common.cacheScrollPage.get(containerObj.attr('id'));
                    if (topBuffer.length > 1) {
                        var curTop = obj.scrollTop;
                        var tt = containerObj.height() * 0.4;
                        for (var i = 0, len = topBuffer.length; i < len; i++) {
                            if (curTop < topBuffer[i] - tt) {
                                containerObj.find('div[name="curr_page_no"]').html('第' + i + '页');
                                break;
                            }
                        }
                    }

                    i4common.cacheScrollTop.remove(containerObj.attr('id'));
                    i4common.cacheScrollTop.put(containerObj.attr('id'), obj.scrollTop);
                    if ((obj.scrollTop + obj.clientHeight) >= obj.scrollHeight - 100) {
                        if (pageNo < 200) {
                            if (!i4common.isLoading(containerObj)) {
                                containerObj.unbind('scroll');
                                i4common.showOrHideLoading(parentContainerObj, containerObj, true, 0, cb);
                            }
                        } else {
                            containerObj.unbind('scroll');
                            i4common.showOrHideLoadEnd(parentContainerObj, containerObj, true, null);
                        }
                    }
                });
            };


            if (containerObj.find('#bottom_loading').length > 0) {
                i4common.showOrHideLoading(parentContainerObj, containerObj, false, 0);
            }
            if (pageNo == 1) {
                containerObj[0].scrollTop = 0;
                //                setTimeout(bindFun, 200);
                bindFun();
            } else {
                bindFun();
            }
        } else {
            var topBuffer = [0];
            if (i4common.cacheScrollPage.containsKey(containerObj.attr('id'))) {
                topBuffer = i4common.cacheScrollPage.get(containerObj.attr('id'));
            }
            topBuffer.push(containerObj[0].scrollHeight);
            i4common.cacheScrollPage.put(containerObj.attr('id'), topBuffer);
            var bindFun = function () {
                if (pageNo == 1) {
                    containerObj[0].scrollTop = 0;
                }
                containerObj.unbind('scroll');
                containerObj.scroll(function () {
                    var obj = containerObj[0];
                    i4common.cacheScrollTop.remove(containerObj.attr('id'));
                    i4common.cacheScrollTop.put(containerObj.attr('id'), obj.scrollTop);
                    var topBuffer = i4common.cacheScrollPage.get(containerObj.attr('id'));
                    if (topBuffer.length > 1) {
                        var curTop = obj.scrollTop;
                        var tt = containerObj.height() * 0.4;
                        for (var i = 0, len = topBuffer.length; i < len; i++) {
                            if (curTop < topBuffer[i] - tt) {
                                containerObj.find('div[name="curr_page_no"]').html('第' + i + '页');
                                break;
                            }
                        }
                    }
                });
            };
            bindFun();
        }
    },

    /**
     * 判断是否加载中。。。
     * @param {} container
     * @return {}
     */
    isLoading: function (container) {
        var flag = false;
        if (container.find('#bottom_loading').length > 0) {
            flag = true;
        }
        return flag;
    },

    /**
     * 显示/隐藏正在加载中
     * @param {} container  显示容器
     * @param {} flag   是否显示 flag=true显示,flag!=true不显示
     */
    showOrHideLoading: function (parentContainerObj, container, flag, speed, cb) {
        if (!speed) {
            speed = 0;
        }
        if (parentContainerObj != null) {
            if (flag) {
                if (container.find('#bottom_loading').length == 0) {
                    parentContainerObj.append('<div class="loading_bar" id="bottom_loading">' +
                        '   <div>' +
                        '       <img width="16" height="16" alt="" src="img/loading_16x16.gif">' +
                        '       <span>正在加载数据，请稍候...</span>' +
                        '   </div>' +
                        '</div>');
                }
                container.find('#bottom_loading').slideDown('fast', function () {
                    var obj = container[0];
                    var sc = obj.scrollHeight - obj.clientHeight - obj.scrollTop;
                    if (speed > 0) {
                        var handler = function () {
                            var t = 0;
                            if (sc > 10) {
                                t = 10;
                                sc = sc - 10;
                            } else {
                                t = sc;
                                sc = 0;
                            }
                            obj.scrollTop = obj.scrollTop + t;
                            if (sc == 0) {
                                clear();
                            }
                        };
                        var timer = setInterval(handler, 20);
                        var clear = function () {
                            clearInterval(timer);
                            if (cb) {
                                cb();
                            }
                        };
                    } else if (speed == -1) {
                        if (cb) {
                            cb();
                        }
                    } else {
                        obj.scrollTop = obj.scrollTop + sc;
                        if (cb) {
                            cb();
                        }
                    }
                });
            } else {
                if (container.find('#bottom_loading').length > 0) {
                    if (speed == 0) {
                        container.find('#bottom_loading').hide().remove();
                        if (cb) {
                            cb();
                        }
                    } else {
                        container.find('#bottom_loading').slideUp('fast', function () {
                            container.find('#bottom_loading').remove();
                            if (cb) {
                                cb();
                            }
                        });
                    }
                }
            }
        }
    },

    showOrHideLoadEnd: function (parentContainerObj, container, flag, cb) {
        if (parentContainerObj != null) {
            if (flag) {
                if (container.find('#bottom_loading_end').length == 0) {
                    parentContainerObj.append('<div class="loading_bar" id="bottom_loading_end">' +
                        '   <div>' +
                        '       <span>没有更多数据</span>' +
                        '   </div>' +
                        '</div>');
                }
                container.find('#bottom_loading_end').slideDown('fast', function () {
                    var obj = container[0];
                    var sc = obj.scrollHeight - obj.clientHeight - obj.scrollTop;
                    var handler = function () {
                        var t = 0;
                        if (sc > 10) {
                            t = 10;
                            sc = sc - 10;
                        } else {
                            t = sc;
                            sc = 0;
                        }
                        obj.scrollTop = obj.scrollTop + t;
                        if (sc == 0) {
                            clear();
                        }
                    };
                    var timer = setInterval(handler, 20);
                    var clear = function () {
                        clearInterval(timer);
                        if (cb) {
                            cb();
                        }
                    };
                });
            } else {
                container.find('#bottom_loading_end').slideUp('fast', function () {
                    container.find('#bottom_loading_end').remove();
                });
            }
        }
    },

    showOrHideLoadEnd2: function (parentContainerObj, container, flag, cb) {
        if (parentContainerObj != null) {
            if (flag) {
                if (container.find('#bottom_loading_end').length == 0) {
                    parentContainerObj.append('<div class="loading_bar" id="bottom_loading_end">' +
                        '   <div>' +
                        '       <span>没有更多数据</span>' +
                        '   </div>' +
                        '</div>');
                }

                if (cb) {
                    cb();
                }
            } else {
                container.find('#bottom_loading_end').slideUp('fast', function () {
                    container.find('#bottom_loading_end').remove();
                });
            }
        }
    },

    showOrHideListLoadError: function (parentContainerObj, container, flag, cb) {
        if (parentContainerObj != null) {
            if (flag) {
                if (container.find('#bottom_loading_error').length == 0) {
                    parentContainerObj.append('<div class="loading_bar" id="bottom_loading_error">' +
                        '   <div>' +
                        '       <span>数据加载失败，<a href="javascript:;" name="reload_list" class="btn_reload">点击重试</a></span>' +
                        '   </div>' +
                        '</div>');
                }
                container.find('#bottom_loading_error').slideDown('fast', function () {
                    var obj = container[0];
                    var sc = obj.scrollHeight - obj.clientHeight - obj.scrollTop;
                    var handler = function () {
                        var t = 0;
                        if (sc > 10) {
                            t = 10;
                            sc = sc - 10;
                        } else {
                            t = sc;
                            sc = 0;
                        }
                        obj.scrollTop = obj.scrollTop + t;
                        if (sc == 0) {
                            clear();
                        }
                    };
                    var timer = setInterval(handler, 20);
                    var clear = function () {
                        clearInterval(timer);
                        if (cb) {
                            cb();
                        }
                    };
                });
            } else {
                container.find('#bottom_loading_error').slideUp('fast', function () {
                    container.find('#bottom_loading_error').remove();
                });
            }
        }
    },


    /**
     * 页面整体加载处理中
     * @param {} flag
     */
    resetLoading: function (flag, divscroll) {
        if (flag) {
            if ($('#' + divscroll).length > 0) {
                $('#' + divscroll).hide();
            }
            $('#all_loading').show();
        } else {
            $('#all_loading').hide();
            if ($('#' + divscroll).length > 0) {
                $('#' + divscroll).show();
                $('#' + divscroll)[0].scrollTop = i4common.cacheScrollTop.get(divscroll);
            }
        }
    },

    /**
     * 无数据场景
     * @param {} flag
     * @param {} divscroll
     */
    noneResult: function (flag, divscroll) {
        $('#all_loading').hide();
        if (flag) {
            $('#' + divscroll).hide();
            $('.loadnone_div').show();
            $('#loadnone_div').show();
        } else {
            $('.loadnone_div').hide();
            $('#loadnone_div').hide();
            $('#' + divscroll).show();
        }
    },

    /**
     * 全局数据加载失败场景
     * @param {} flag
     * @param {} divscroll
     */
    failResult: function (flag, divscroll) {
        $('#all_loading').hide();
        if (flag) {
            $('#' + divscroll).hide();
            $('#loadfail_div').show();
        } else {
            $('#loadfail_div').hide();
            $('#' + divscroll).show();
        }
    },


    /**
     * 发送ajax请求包装
     * url : 请求方法路径
     * param : 请求参数 : json对象
     * successCB : 成功返回时的回调函数  回调函数中返回data　：即后台返回数据 ,
     *          说明 ：在successCB中不负责当前请求后台返回数据是否正确，只保证此次请求是以状态 200 回来的请求
     * errorCB : 请求错误回调 , 回调函数中返回errorObj
     * cacheType : 缓存操作
     */
    ajax: function (url, param, successCB, errorCB, postType, dataType, cacheType) {
        postType = (!postType) ? 'POST' : postType;
        cacheType = (cacheType == null) ? false : cacheType;
        dataType = (dataType == null) ? 'json' : dataType;
        if (i4common.DEBUG && url.indexOf('http') == -1) {

            url = 'http://app4.i4.cn' + url;
            // url = "http://120.27.160.46:81" + url;
            // dataType = "jsonp";
        }
        $.ajax({
            url: url,
            data: param,
            timeout: 10000, //超时时间设置，单位毫秒
            cache: cacheType,
            type: postType,
            xhrFields: {
                withCredentials: true // 允许跨域请求时携带COOKIE
            },
            dataType: dataType,
            success: function (data) {
                if (successCB) {
                    successCB(data);
                }
            },
            error: function (errorObj) {
                if (errorCB) {
                    errorCB(errorObj);
                } else {
                    //alert("请求数据失败，请稍后再试！");
                }
            }
        });
    },

    /**
     * 下载量转换
     * @param {} number
     * @return {}
     */
    convertNum: function (number, dec) {
        var num = number;
        if (num < 0) {
            num = 0;
        } else {
            var decNum = '1';
            for (var i = 0; i < dec; i++) {
                decNum += '0';
            }
            if (!isNaN(number)) {
                if (number >= 100000) {
                    num = Math.round(number / 10000 * parseInt(decNum)) / parseInt(decNum) + '万';
                }
            }
        }
        return num;
    },

    converNum2: function (number) {
        var num = number;
        if (num < 0) {
            num = 0;
        } else {
            if (!isNaN(number)) {
                if (number >= 100000000) {
                    num = Math.round((number / 100000000) * 100) / 100 + '亿';
                } else if (number >= 1000000) {
                    num = Math.round(number / 10000) + '万';
                } else if (number >= 10000) {
                    num = Math.round((number / 10000) * 10) / 10 + '万';
                }
            }
        }
        return num;
    },

    /**
     * 时间转换
     * @param {} second
     * @return {}
     */
    convertTime: function (second) {
        var rtTime = '';
        if (second > 60) {
            var minute = Math.floor(second / 60);
            var sec = second - (minute * 60);
            rtTime = (minute < 10 ? '0' + minute : minute) + ':' + (sec < 10 ? '0' + sec : sec);
        } else {
            rtTime = '00:' + (second < 10 ? '0' + second : second);
        }
        return rtTime;
    },

    /**
     * 阻止冒泡
     */
    stopBubble: function (e) {
        e.preventDefault();
        e.stopPropagation();
    },

    /**
     * 铃声文件大小转换
     * @param {} size
     */
    convertSize: function (bytesize) {
        var size = bytesize;
        if (!isNaN(bytesize)) {
            if (bytesize > 1024) {
                size = bytesize / 1024;
                if (size > 1024) {
                    size = size / 1024;
                    if (size > 1024) {

                        size = Math.round(size * 100) / 100 + 'GB';
                    } else {
                        size = Math.round(size * 100) / 100 + 'MB';
                    }
                } else {
                    size = Math.round(size * 100) / 100 + 'KB';
                }
            } else {
                size = Math.round(size * 100) / 100 + 'B';
            }
        }
        return size;
    },
    /**
     * 应用文件大小转换
     * @param {} size
     */
    appConverSize: function (limit) {
        limit = parseInt(limit);
        var size = '';
        if (limit < 0.9 * 1024) { //如果小于0.1KB转化成B
            size = limit.toFixed(2) + 'B';
        } else if (limit < 0.9 * 1024 * 1024) {//如果小于0.1MB转化成KB
            size = (limit / 1024).toFixed(2) + 'KB';
        } else if (limit < 0.9 * 1024 * 1024 * 1024) { //如果小于0.1GB转化成MB
            size = (limit / (1024 * 1024)).toFixed(2) + 'MB';
        } else { //其他转化成GB
            size = (limit / (1024 * 1024 * 1024)).toFixed(2) + 'GB';
        }

        var sizestr = size + '';
        var len = sizestr.indexOf('\.');
        var dec = sizestr.substr(len + 1, 2);
        if (dec == '00') {//当小数点后为00时 去掉小数部分
            return sizestr.substring(0, len) + sizestr.substr(len + 3, 2);
        }
        return sizestr;
    },
    /**
     * 发送ajax跨域请求包装
     * url : 请求方法路径
     * param : 请求参数 : json对象
     * successCB : 成功返回时的回调函数  回调函数中返回data　：即后台返回数据 ,
     *          说明 ：在successCB中不负责当前请求后台返回数据是否正确，只保证此次请求是以状态 200 回来的请求
     * errorCB : 请求错误回调 , 回调函数中返回errorObj
     * cacheType : 缓存操作
     */
    ajaxJsonp: function (url, param, successCB, errorCB, cacheType) {
        cacheType = (cacheType == null) ? false : cacheType;
        $.ajax({
            url: url,
            data: param,
            timeout: 10000, //超时时间设置，单位毫秒
            cache: cacheType,
            type: 'GET',
            dataType: 'jsonp',
            jsonp: 'jsoncallback',
            success: function (data) {
                if (successCB) {
                    successCB(data);
                }
            },
            error: function (errorObj) {
                if (errorCB) {
                    errorCB(errorObj);
                } else {
                    //alert("请求数据失败，请稍后再试！");
                }
            }
        });
    },

    /**
     * 按字节截取字符串
     * @param {} str
     * @param {} len
     * @return {}
     */
    subStringByByte: function (str, len) {
        var rtStr = '';
        try {
            var strLen = Math.ceil(str.replace(/[^\x00-\xff]/g, 'aa').replace(/[A-Z]/g, 'bb').length / 2);
        } catch (error) {

        }

        if (strLen > len) {
            var tmpLen = 0;
            var tmpStr = '';
            var chaAr = str.split('');
            for (var i = 0; i < chaAr.length; i++) {
                tmpStr = tmpStr + chaAr[i];
                if (Math.ceil(tmpStr.replace(/[^\x00-\xff]/g, 'aa').replace(/[A-Z]/g, 'bb').length / 2) <= len - 1) {
                    rtStr = tmpStr;
                } else {
                    break;
                }
            }
            rtStr = rtStr + '...';
        } else {
            rtStr = str;
        }
        return rtStr;
    },

    /**
     * 显示html特殊字符
     */
    showHtmlSpecialChar: function (str) {
        if (str) {
            return str.replace(/&quot;/g, '"').replace(/&apos;/g, '\'').replace(/&#039;/g, '\'').replace(/&gt;/g, '>').replace(/&lt;/g, '<').replace(/&amp;/, '&');
        }
        return '';
    },

    /**
     * 转义html特殊字符
     */
    escapeHtmlSpecialChar: function (str) {
        if (str) {
            return str.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g,
                '&gt;').replace(/"/g, '&quot;');
        }
        return '';
    },


    /**
     * 比较两个版本号大小
     * [0, v1=v2]; [1, v1>v2]; [-1, v1<v2]
     * @param {} v1
     * @param {} v2
     * @return {}
     */
    comperVersion: function (v1, v2) {
        var re = 0;
        var v1_ar = v1.split('.');
        var v2_ar = v2.split('.');
        for (var i = 0; i < v1_ar.length && i < v2_ar.length; i++) {
            if (parseInt(v1_ar[i]) > parseInt(v2_ar[i])) {
                re = 1;
                break;
            } else if (parseInt(v1_ar[i]) < parseInt(v2_ar[i])) {
                re = -1;
                break;
            } else {
                re = 0;
            }
        }
        if (re == 0) {
            if (v1_ar.length > v2_ar.length) {
                re = 1;
            } else if (v1_ar.length > v2_ar.length) {
                re = -1;
            } else {
                re = 0;
            }
        }
        return re;
    },

    mouseRightEvent: function () {
        var re = i4common.comperVersion(i4common.pc_vs, '7.11.008');
        if (re < 1) {
            return false;
        }
    },
};
